# -*-  coding: UTF-8 -*-

#最后修改时间，



import wx
import sys, os, glob
import vdh, vdh_dl
import re

class DemoFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1,
                          "Video Download Helper",
                          size=(600,400))
        il = wx.ImageList(32,32, True)
        for name in glob.glob("iMovie.png"):
            bmp = wx.Bitmap(name, wx.BITMAP_TYPE_PNG)
            il.Add(bmp)
        for name in glob.glob("iTunes.png"):
            bmp = wx.Bitmap(name, wx.BITMAP_TYPE_PNG)
            il.Add(bmp)
        self.list = wx.ListCtrl(self, -1,
                                style=wx.LC_ICON | wx.LC_AUTOARRANGE)
        self.list.AssignImageList(il, wx.IMAGE_LIST_NORMAL)

        vdh.listvideo()
        for x in range(len(vdh.filelist) - 1):
            if "flv" in re.findall(r'flv', vdh.filelist[x + 1]):
                self.list.InsertImageStringItem(x,
                                                str(os.path.basename(vdh.filelist[x + 1])),
                                                0)
            elif "mp3" in re.findall(r'mp3', vdh.filelist[x + 1]):
                self.list.InsertImageStringItem(x,
                                                str(os.path.basename(vdh.filelist[x + 1])),
                                                1)

        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.OnItemRightClick, self.list)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnDoubleClick, self.list)

    def OnItemRightClick(self, event):          #定义鼠标右击事件
        n = event.GetIndex()
        vdh_dl.RunDialog(n)

    def OnDoubleClick(self, event):             #定义鼠标双击事件
        n = event.GetIndex()
        vdh.viewvideo(n)
    
app = wx.PySimpleApp()
frame = DemoFrame()
frame.Show()
app.MainLoop()
